package com.ruoyi.server.api.imgmanage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.ImgType;
import com.ruoyi.server.api.imgtype.service.IImgTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.server.api.imgmanage.domain.ImgManage;
import com.ruoyi.server.api.imgmanage.service.IImgManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管理各种类型图片Controller
 * 
 * @author ruoyi
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/imgmanage/imgmanage")
public class ImgManageController extends BaseController
{
    @Autowired
    private IImgManageService imgManageService;
    @Autowired
    private IImgTypeService iImgTypeService;

    /**
     * 查询管理各种类型图片列表
     */
    @PreAuthorize("@ss.hasPermi('imgmanage:imgmanage:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImgManage imgManage)
    {
        startPage();
        List<ImgManage> list = imgManageService.selectImgManageList(imgManage);
        return getDataTable(list);
    }

    /**
     * 导出管理各种类型图片列表
     */
    @PreAuthorize("@ss.hasPermi('imgmanage:imgmanage:export')")
    @Log(title = "管理各种类型图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImgManage imgManage)
    {
        List<ImgManage> list = imgManageService.selectImgManageList(imgManage);
        ExcelUtil<ImgManage> util = new ExcelUtil<ImgManage>(ImgManage.class);
        util.exportExcel(response, list, "管理各种类型图片数据");
    }

    /**
     * 获取管理各种类型图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('imgmanage:imgmanage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imgManageService.selectImgManageById(id));
    }

    @GetMapping(value = "/selectImgByTypeId")
    public AjaxResult selectImgByTypeId(Long id)
    {
        return success(imgManageService.selectImgByTypeId(id)
        );
    }

    /**
     * 新增管理各种类型图片
     */
    @PreAuthorize("@ss.hasPermi('imgmanage:imgmanage:add')")
    @Log(title = "管理各种类型图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImgManage imgManage)
    {
        return toAjax(imgManageService.insertImgManage(imgManage));
    }

    /**
     * 修改管理各种类型图片
     */
    @PreAuthorize("@ss.hasPermi('imgmanage:imgmanage:edit')")
    @Log(title = "管理各种类型图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImgManage imgManage)
    {
        return toAjax(imgManageService.updateImgManage(imgManage));
    }

    /**
     * 删除管理各种类型图片
     */
    @PreAuthorize("@ss.hasPermi('imgmanage:imgmanage:remove')")
    @Log(title = "管理各种类型图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imgManageService.deleteImgManageByIds(ids));
    }

    /**
     * 获取树列表
     */
    @PreAuthorize("@ss.hasPermi('imgmanage:imgmanage:list')")
    @GetMapping("/iImgTypeTree")
    public AjaxResult deptTree(ImgType imgType)
    {
        return success(iImgTypeService.selectImgTypeTreeList(imgType));
    }

    /**
     * @Author zsc
     * @Description 获取一个月之内上新的产品
     * @Date 2024/10/24 16:16
     * @Return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping(value = "/selectImgNewestByTypeId")
    public AjaxResult selectImgNewestByTypeId()
    {
        return success(imgManageService.selectImgNewestByTypeId()
        );
    }
}
